package com.itheima.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.text.SimpleDateFormat;

@WebServlet("/sec01")
public class ServletSession01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //获取请求中的用户名
        String username = req.getParameter("username");
        //查看session有没有，有直接获取，没有创建
        HttpSession session = req.getSession();
        System.out.println(session);
        System.out.println(session.getId());
       //将用户信息添加到共享数据
        session.setAttribute("username", username);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
